 <?php

include_once 'db/Crud.php';
class Agenda extends Crud {
    
    protected $table = "agenda";
    private $data;
    private $hora;
    private $idUsuario;
    private $idFuncionario;
    private $idCargo;
    private $status;
    private $justificativa;
    private $tipo;
    private $previsao;
    
    public function getData() {
        return $this->data;
    }

    public function getHora() {
        return $this->hora;
    }

    public function getIdUsuario() {
        return $this->idUsuario;
    }

    public function getIdFuncionario() {
        return $this->idFuncionario;
    }

    public function getIdCargo() {
        return $this->idCargo;
    }

    public function getStatus() {
        return $this->status;
    }

    public function getJustificativa() {
        return $this->justificativa;
    }

    public function getTipo() {
        return $this->tipo;
    }

    public function getPrevisao() {
        return $this->previsao;
    }

    public function setData($data) {
        $this->data = $this->dateToUS($data);
    }

    public function setHora($hora) {
        $this->hora = $hora;
    }

    public function setIdUsuario($idUsuario) {
        $this->idUsuario = $idUsuario;
    }

    public function setIdFuncionario($idFuncionario) {
        $this->idFuncionario = $idFuncionario;
    }

    public function setIdCargo($idCargo) {
        $this->idCargo = $idCargo;
    }

    public function setStatus($status) {
        $this->status = $status;
    }

    public function setJustificativa($justificativa) {
        $this->justificativa = $justificativa;
    }

    public function setTipo($tipo) {
        $this->tipo = $tipo;
    }

    public function setPrevisao($previsao) {
        $this->previsao = $previsao;
    }

    public function insert() {
        $sql = "INSERT INTO $this->table (age_data, age_hora, age_usu_id, age_fun_id, age_car_id, age_status, age_tipo, age_previsao) VALUES (:data, :hora, :idUsuario, :idFuncionario, :idCargo, :status, :tipo, :previsao)";
        $stmt = Db::prepare($sql);
        $stmt->bindParam(':data', $this->data);
        $stmt->bindParam(':hora', $this->hora);
        $stmt->bindParam(':idUsuario', $this->idUsuario);
        $stmt->bindParam(':idFuncionario', $this->idFuncionario);
        $stmt->bindParam(':idCargo', $this->idCargo);
        $stmt->bindParam(':status', $this->status);
        $stmt->bindParam(':tipo', $this->tipo);
        $stmt->bindParam(':previsao', $this->previsao);
        return $stmt->execute();  
        
    }

    public function update($id) {
        
        $sql = "UPDATE $this->table SET age_status = :status WHERE id = :id";
        $stmt = Db::prepare($sql);
        $stmt->bindParam(':status', $this->status);
        $stmt->bindParam(':id', $id);
        return $stmt->execute();
        
    }
    
    public function verificaagenda($data, $hora, $idprofissional) {
        $sql = "SELECT * FROM $this->table WHERE age_data = :data AND age_hora = :hora AND age_fun_id = :profissional ORDER BY id DESC";
        $stmt = Db::prepare($sql);
        $stmt->bindParam(':data', $data);
        $stmt->bindParam(':hora', $hora);
        $stmt->bindParam(':profissional', $idprofissional);
        $stmt->execute();
        return $stmt->fetchAll(PDO::FETCH_CLASS);
        
    }
    
    public function listaagenda($data) {
        
        $sql = "SELECT * FROM $this->table WHERE age_data = :data AND age_status = 'A' ORDER BY age_hora ASC";
        $stmt = Db::prepare($sql);
        $stmt->bindParam(':data', $data);
        $stmt->execute();
        return $stmt->fetchAll(PDO::FETCH_CLASS);
        
    }
    
    public function buscaragenda($idUsuario) {
        
        $sql = "SELECT * FROM $this->table WHERE age_usu_id = :idUsuario ORDER BY id ASC";
        $stmt = Db::prepare($sql);
        $stmt->bindParam(':idUsuario', $idUsuario);
        $stmt->execute();
        return $stmt->fetchAll(PDO::FETCH_CLASS);
        
    }
	
	public function listanomeagenda($idusuario){
	
		$sql = "SELECT * FROM $this->table, funcionario, cargo WHERE agenda.age_usu_id = :idUsuario AND agenda.age_fun_id = funcionario.id AND agenda.age_car_id = cargo.id ORDER BY agenda.id ASC";
        $stmt = Db::prepare($sql);
        $stmt->bindParam(':idUsuario', $idusuario);
        $stmt->execute();
        return $stmt->fetchAll(PDO::FETCH_CLASS);
	
	}
	
	

}
